package com.szx.usercenter.handle;

import com.szx.usercenter.util.ResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 自定义全局异常处理类
 * @author songzx
 * @date 2024/5/12
 * @apiNote
 */
@Data
public class CenterExceptionHandler extends RuntimeException{
    /**
     * 错误码
     */
    private String code;

    /**
     * 业务异常
     *
     * @param message     信息
     * @param code        错误码
     */
    public CenterExceptionHandler(String message, String code) {
        super(message);
        this.code = code;
    }

    /**
     * 业务异常
     *
     * @param errorCode 错误代码
     */
    public CenterExceptionHandler(ResponseEnum errorCode) {
        super(errorCode.getMsg());
        this.code = errorCode.getCode();
    }

    /**
     * 默认业务异常，状态默认500
     *
     * @param message 信息
     */
    public CenterExceptionHandler(String message) {
        super(message);
        this.code = ResponseEnum.ERROR.getCode();
    }

    /**
     * 默认业务异常
     */
    public CenterExceptionHandler() {
        super(ResponseEnum.ERROR.getMsg());
        this.code = ResponseEnum.ERROR.getCode();
    }
}
